package com.sx.epidemic_system.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sx.epidemic_system.entity.MapValue2;
import com.sx.epidemic_system.entity.ResultVo;
import com.sx.epidemic_system.entity.Total;
import com.sx.epidemic_system.mapper.TotalMapper;
import com.sx.epidemic_system.service.NewAddService;
import com.sx.epidemic_system.service.TotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Service
public class TotalServiceImpl  implements TotalService {

    @Autowired
    TotalMapper totalMapper;
    @Resource
    NewAddService newAddService;

    @Override
    public Total totalCount(String province) {
        return totalMapper.totalCount(province);
    }

    @Override
    public Total totalForeignCount(String province) {
        return totalMapper.totalForeignCount(province);
    }

    @Override
    public Total totalCure(String province) {
        return totalMapper.totalCure(province);
    }

    @Override
    public Total totalDead(String province) {
        return totalMapper.totalDead(province);
    }

    @Override
    public ResultVo tableList(Integer page , Integer limit) {


       List<MapValue2> list=totalMapper.tableList();
        /*List<String> province = totalMapper.tableList();
        for (int i = 0; i < province.size(); i++) {
            MapValue2 m = new MapValue2();

            if(newAddService.getAllNewAddProvince(province.get(i))!=0||newAddService.getAsymptomaticProvince(province.get(i))!=0)
            {
                m.setProvince(province.get(i));
                m.setNewCount(newAddService.getAllNewAddProvince(province.get(i)));
                m.setNewCount2(newAddService.getAsymptomaticProvince(province.get(i)));
                list.add(m);
            }


        }*/
        Collections.sort(list, new Comparator<MapValue2>() {
            @Override
            public int compare(MapValue2 o1, MapValue2 o2) {
                //第一个参数属性 - 第二个参数属性 = 升序排序
                //第二个参数属性 - 第一个参数属性 = 降序排序
                return o2.getNewCount()-o1.getNewCount();
            }
        });

        ResultVo rs=new ResultVo();
        PageHelper.startPage( page , limit);
        rs.setCode(0);
        PageInfo<MapValue2> pageInfo = new PageInfo<>(list);
        rs.setData(pageInfo.getList());
        rs.setCount(pageInfo.getTotal());
        return rs;
    }
}
